<?php
namespace submodule\modules\feedback\components;


use yii\db\Schema;
use yii\db\Migration;

class Uninstaller extends Migration
{
    //安装
    public function install($option)
    {
		//建表
        $this->db->createCommand()->createTable('{{%'.$option['tablename'].'}}', [
            'id'=>  "pk",
			'content'=> "mediumtext NOT NULL",
			'userid'=> "int(11) NOT NULL",
			'contact'=> "varchar(128) NOT NULL",
			'platform'=> "tinyint(1) default NULL COMMENT '1android 2 ios'",
			'devicename'=> "varchar(250) default NULL",
			'osversion'=> "varchar(10) default NULL",
			'appversion'=> "varchar(15) default NULL",
			'addtime'=> "int(10) NOT NULL",
			'isread'=> "tinyint(1) NOT NULL default '0' COMMENT '0代表未读，1代表已读'",
        ],'ENGINE InnoDB DEFAULT CHARSET utf8')->execute();


		
		//记录字段
		$fields = ['modelid', 'name', 'field', 'formtype', 'fieldtype', 'fieldlength', 'listorder', 'disabled', 'primarytable', 'required', 'setting', 'param', 'api', 'allowinput'];

		
		$rows = [
		     [$option['modelid'], 'ID', 'id', 'primarykey', 'int', 10, 0, 0, 2, 1, '', '', '', 0], 
			 [$option['modelid'], '用户', 'userid', 'text', 'int', 10, 0, 0, 2, 1, '', '', '', 1], 
			 [$option['modelid'], '联系方式', 'contact', 'text', 'varchar', 128, 0, 0, 1, 1, '', '', '', 1], 
			 [$option['modelid'], '终端类型', 'platform', 'text', 'tinyint', 1, 0, 0, 1, 1, '', '', '', 0], 
			 [$option['modelid'], '终端名称', 'devicename', 'text', 'varchar', 250, 0, 0, 1, 1, '', '', '', 0], 
			 [$option['modelid'], '终端系统版本', 'osversion', 'text', 'varchar', 10, 0, 0, 1, 1, '{"defaultvalue":"0"}', '', '', 0], 
			 [$option['modelid'], '应用版本', 'appversion', 'text', 'varchar', 10, 0, 0, 1, 1, '', '', '', 0], 
			 [$option['modelid'], '添加时间', 'addtime', 'text', 'int', 10, 0, 0, 1, 1, '', '', '', 0], 
			 [$option['modelid'], '内容', 'content', 'ueditor', '', 150, 0, 0, 1, 0, '', '', '', 1],
			 [$option['modelid'], '已读状态', 'isread', 'switch', 'int', 10, 0, 0, 1, 1, '', '', '', 1], 
	    ];
		$this->db->createCommand()->batchInsert($option['field_tablename'], $fields, $rows)->execute();
		
    }
    
	
	//卸载
    public function uninstall()
    {
        $this->dropTable('{{store_product}}');
    }
}
